package com.ruimei.util;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import java.io.PrintStream;

/**
 * 阿里云短信
 */

public class SmsUtils
{
  static final String product = "Dysmsapi";
  static final String domain = "dysmsapi.aliyuncs.com";
  static final String accessKeyId = "LTAIEMkfi7g8Vkgh";
  static final String accessKeySecret = "dwxHTAdBEEEHZTMCOQP90pymOWJG5n";
  private static int newcode;
  
  public static SendSmsResponse sendSms(String telephone, String code)
    throws ClientException
  {
    System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
    System.setProperty("sun.net.client.defaultReadTimeout", "10000");
    
    IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIEMkfi7g8Vkgh", "dwxHTAdBEEEHZTMCOQP90pymOWJG5n");
    DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com");
    IAcsClient acsClient = new DefaultAcsClient(profile);
    
    SendSmsRequest request = new SendSmsRequest();
    
    request.setPhoneNumbers(telephone);
    
    request.setSignName("攀枝花市南山实验学校");
    
    request.setTemplateCode("SMS_146280933");
    
    request.setTemplateParam("{\"code\":\"" + code + "\"}");
    
    request.setOutId("yourOutId");
    
    SendSmsResponse sendSmsResponse = (SendSmsResponse)acsClient.getAcsResponse(request);
    if ((sendSmsResponse.getCode() != null) && (sendSmsResponse.getCode().equals("OK"))) {
      System.out.println("短信发送成功！");
    } else {
      System.out.println("短信发送失败！");
    }
    return sendSmsResponse;
  }
  
  public static int getNewcode()
  {
    return newcode;
  }
  
  public static void setNewcode()
  {
    newcode = (int)(Math.random() * 9999.0D) + 100;
  }
  
  public static void main(String[] args)
    throws Exception
  {
    setNewcode();
    String code = Integer.toString(getNewcode());
    SendSmsResponse sendSms = sendSms("13518192225", code);
    
    System.out.println("短信接口返回的数据----------------");
    System.out.println("Code=" + sendSms.getCode());
    System.out.println("Message=" + sendSms.getMessage());
    System.out.println("RequestId=" + sendSms.getRequestId());
    System.out.println("BizId=" + sendSms.getBizId());
  }
}


/* Location:              E:\360MoveData\Users\admin\Desktop\teacher_wap-0.0.1-SNAPSHOT.jar!\BOOT-INF\classes\com\ruime\\util\SmsUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       0.7.1
 */